/**
 * Project:   dtu.fmes.googleloon
 * File:      Vector.java
 * License: 
 *            This file is licensed under GNU General Public License version 3
 *            http://www.gnu.org/licenses/gpl-3.0.txt
 *
 * Copyright:	Nicolai Sonne [ NicolaiSonne@hotmail.com.com ]
 * Date:      Dec 11, 2013
 */

package dtu.fmes.loon.model;

import java.io.Serializable;

/**
 * Simple class for holding x,y coordinates. Includes possibilities of added and dividing vector
 * 
 * @author Nicolai Sonne
 */
public class Vector implements Serializable {

	private static final long serialVersionUID = 7589651896884285380L;

	private Double x = null;

	private Double y = null;

	public Vector() {
		super();
	}

	public Vector(Double x, Double y) {
		super();
		this.x = x;
		this.y = y;
	}

	/**
	 * Add x,y coordinates of another vector to this one.
	 * 
	 * @param vector
	 */
	public void add(Vector vector) {
		x += vector.getX();
		y += vector.getY();
	}

	@Override
	protected Object clone() throws CloneNotSupportedException {
		return new Vector(x, y);
	}

	/**
	 * Divides x and y by given parameter
	 * 
	 * @param divider
	 */
	public void divide(Double divider) {
		x = x / divider;
		y = y / divider;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Vector other = (Vector) obj;
		if (x == null) {
			if (other.x != null) {
				return false;
			}
		} else if (!x.equals(other.x)) {
			return false;
		}
		if (y == null) {
			if (other.y != null) {
				return false;
			}
		} else if (!y.equals(other.y)) {
			return false;
		}
		return true;
	}

	public Double getX() {
		return x;
	}

	public Double getY() {
		return y;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (x == null ? 0 : x.hashCode());
		result = prime * result + (y == null ? 0 : y.hashCode());
		return result;
	}

	public void setX(Double x) {
		this.x = x;
	}

	public void setY(Double y) {
		this.y = y;
	}

	@Override
	public String toString() {
		return "Vector [x=" + x + ", y=" + y + "]";
	}

}
